#!/bin/bash
# 作用：启/停Maxwell服务
MAXWELL_HOME=/opt/module/maxwell-1.29.2

status_maxwell(){
	result=`ps -ef | grep com.zendesk.maxwell.Maxwell | grep -v grep | wc -l`
	return $result
}

start_maxwell(){
	status_maxwell
	if [[ $? -lt 1 ]]
	then
		echo "========== 启动Maxwell =========="
		$MAXWELL_HOME/bin/maxwell --config $MAXWELL_HOME/config.properties --daemon
	else
		echo "Maxwell已经启动！"
	fi
}

stop_maxwell(){
	status_maxwell
	if [[ $? -gt 0 ]]
	then
		echo "========== 关闭Maxwell =========="
		ps -ef | grep maxwell | grep -v grep | awk '{print $2}' | xargs kill -9
	else
		echo "Maxwell还没启动！"
	fi
}

if [ $# -ne 1 ]
then
	echo "请输入正确指令start/stop/status" && exit
fi

case $1 in
"start")
	start_maxwell
;;
"stop")
	stop_maxwell
;;
"status")
	status_maxwell
	if [ $? -eq 1 ]
	then
		echo "Maxwell正在运行!"
	else
		echo "Maxwell不在运行！"
	fi
;;
esac
